/**
 * MenuListAdapter
 * 
 * 03/11/2013
 * 
 * Copyright GPL
 */
package com.jtmproject.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jtmproject.R;
import com.jtmproject.classes.ListMenuItem;
import com.jtmproject.classes.MenuItem;

/**
 * this is an adapter to charge the Listview on the MainMenu
 * @author Javier Tejedor
 */
public class MenuListAdapter extends BaseAdapter {
	
	private Activity activity;
	private ListMenuItem listMenuItem;

	/**
	 * constructor
	 * @param activity
	 * @param newList
	 */
	public MenuListAdapter(Activity activity, ListMenuItem listMenuItem) {
		this.activity = activity;
		this.listMenuItem = listMenuItem;
	}
	
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		return listMenuItem.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		return listMenuItem.get(position);
	}
	
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, 
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		
		if(convertView == null){
			LayoutInflater inflater = 
					(LayoutInflater) activity.getSystemService(
							Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.item_main_menu_list, null);
		}
		
		MenuItem item = listMenuItem.get(position);
		
		ImageView imageItem = (ImageView) view.findViewById(R.id.icon_item);
		imageItem.setImageResource(item.getImageResource());
		
		TextView textViewTitle = (TextView) view.findViewById(R.id.title_item);
		textViewTitle.setText(item.getTitle());
	
		return view;
	}

}
